33 Lecture

CS402

Midterm & Final Term Short Notes

Polish Notation

Polish notation, also known as prefix notation, is a way of writing mathematical expressions without using parentheses to indicate the order of operations. In this notation, each operator is placed before its operands, rather than between them a


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. Which of the following is an example of Polish notation? a) 3 + 4 b) + 3 4 c) 3 4 + d) 4 3 + Answer: b) + 3 4 Polish notation is also known as: a) Infix notation b) Postfix notation c) Prefix notation d) None of the above Answer: c) Prefix notation In Polish notation, each operator is placed: a) After its operands b) Between its operands c) Before its operands d) None of the above Answer: c) Before its operands The expression "5 + 8 - 2" in Polish notation would be written as: a) + 5 8 2 b) - 2 + 5 8 c) - + 5 8 2 d) None of the above Answer: c) - + 5 8 2 Which of the following is an advantage of using Polish notation? a) It eliminates the need for operators b) It eliminates the need for parentheses c) It eliminates the need for operands d) None of the above Answer: b) It eliminates the need for parentheses The evaluation of Polish notation expressions is based on: a) Precedence rules b) Associativity rules c) A stack-based algorithm d) None of the above Answer: c) A stack-based algorithm The inventor of Polish notation was: a) John McCarthy b) Jan Lukasiewicz c) Alan Turing d) Claude Shannon Answer: b) Jan Lukasiewicz Which of the following programming languages uses Polish notation for function calls? a) Lisp b) C++ c) Python d) Java Answer: a) Lisp Which of the following is an example of a valid Polish notation expression? a) + * 2 3 4 b) * 2 3 + c) / 4 - 6 2 d) None of the above Answer: a) + * 2 3 4 Which of the following is not an advantage of using Polish notation? a) It is easily parsable by computers b) It eliminates ambiguity in expressions c) It allows for easy evaluation using a stack-based algorithm d) It requires fewer keystrokes than infix notation Answer: d) It requires fewer keystrokes than infix notation


Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the Polish notation? Answer: Polish notation, also known as prefix notation, is a way of writing arithmetic expressions in which the operators are placed before their operands. Who introduced the Polish notation? Answer: Polish notation was introduced by the Polish mathematician Jan Lukasiewicz in the 1920s. What are the advantages of using Polish notation? Answer: The advantages of using Polish notation are that it eliminates the need for parentheses and removes ambiguity in the order of operations. How do you evaluate an expression in Polish notation? Answer: To evaluate an expression in Polish notation, you start from the left and read the expression from right to left. When you encounter an operator, you apply it to the two most recent operands in the stack. What is the reverse Polish notation? Answer: Reverse Polish notation (RPN), also known as postfix notation, is a way of writing arithmetic expressions in which the operators are placed after their operands. What are the advantages of using reverse Polish notation? Answer: The advantages of using reverse Polish notation are that it eliminates the need for parentheses and removes ambiguity in the order of operations, just like Polish notation. What is the difference between Polish notation and reverse Polish notation? Answer: The main difference between Polish notation and reverse Polish notation is the placement of the operators: Polish notation places the operators before the operands, while reverse Polish notation places the operators after the operands. What is the role of a stack in evaluating expressions in Polish notation? Answer: A stack is used to store the operands as they are encountered while reading the expression. When an operator is encountered, the two most recent operands are popped from the stack, the operation is performed, and the result is pushed back onto the stack. Can all expressions be written in Polish notation or reverse Polish notation? Answer: Yes, all expressions can be written in Polish notation or reverse Polish notation. What is the complexity of evaluating expressions in Polish notation and reverse Polish notation? Answer: The complexity of evaluating expressions in Polish notation and reverse Polish notation is O(n), where n is the length of the expression. This makes them very efficient for evaluating expressions in computer programs.

Polish notation is a prefix notation for arithmetic expressions in which every operator precedes its operands. It is also called prefix notation, as the operator comes before the operands. For example, the expression 4 + 5 can be represented in Polish notation as + 4 5. Here are some of the features of Polish notation:
  • It eliminates the need for parentheses in the expression.
  • It is unambiguous, and there is only one way to evaluate a given expression in Polish notation.
  • It is used in computer science for evaluating arithmetic expressions and building syntax trees.
To evaluate an arithmetic expression in Polish notation, we start from the left and read each operator and its operands in sequence. For example, to evaluate the expression + * 2 3 4, we first evaluate the multiplication operation * 2 3 to get 6, and then evaluate the addition operation + 6 4 to get the result 10. Polish notation is named after the Polish mathematician Jan ?ukasiewicz, who introduced it in the 1920s. It is commonly used in computer science for the manipulation and evaluation of arithmetic expressions. It is also used in logic and linguistics, where it is called ?ukasiewicz notation. Polish notation has several advantages over other notations. For example, it is easier to evaluate expressions in Polish notation because it eliminates the need for parentheses. It is also easier to implement in computer programs because it can be evaluated using a stack data structure.